/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package DataModel;

import java.util.Arrays;
import java.util.Objects;
import org.joda.time.DateTime;

/**
 *
 * @author Tomasz Nowak
 */
public class NotaryEntry
{
	NotaryCertificate notaryCertificate;

	public NotaryCertificate getNotaryCertificate()
	{
		return notaryCertificate;
	}

	public void setNotaryCertificate( NotaryCertificate notaryCertificate )
	{
		this.notaryCertificate = notaryCertificate;
	}

	private EntryStatus status;
	private DateTime dateTime;

	public static final String NAME_STRING = "Name";
	public static final String PUBLIC_KEY_STRING = "PublicKey";
	public static final String ENTRY_STATUS_STRING = "EntryStatus";
	public static final String DATE_STRING = "Date";

	public NotaryEntry()
	{
	}

	@Override
	public int hashCode()
	{
		int hash = 7;
		hash = 79 * notaryCertificate.hashCode() + hash;
		hash = 79 * hash + Objects.hashCode(this.status);
		hash = 79 * hash + Objects.hashCode(this.dateTime);
		return hash;
	}

	@Override
	public boolean equals( Object obj )
	{
		if ( obj == null )
		{
			return false;
		}
		if ( getClass() != obj.getClass() )
		{
			return false;
		}
		final NotaryEntry other = ( NotaryEntry ) obj;
		if ( !Objects.equals(this.notaryCertificate, other.notaryCertificate) )
		{
			return false;
		}
		if ( this.status != other.status )
		{
			return false;
		}
		if ( !Objects.equals(this.dateTime, other.dateTime) )
		{
			return false;
		}
		return true;
	}

	@Override
	public String toString()
	{
		return "NotaryEntry{" + "name=" + notaryCertificate.getName() + ", publicKey=" + notaryCertificate.getPublicKey() + ", status=" + status + ", dateTime=" + dateTime + '}';
	}

	public NotaryEntry( String name, byte[] publicKey, EntryStatus status, DateTime dateTime )
	{
		this.notaryCertificate = new NotaryCertificate(name, publicKey);
		this.status = status;
		this.dateTime = dateTime;
	}

	public NotaryEntry( String name, byte[] publicKey, DateTime dateTime )
	{
		this(name, publicKey, EntryStatus.Revocated, dateTime);
	}

	public EntryStatus getStatus()
	{
		return status;
	}

	public void setStatus( EntryStatus status )
	{
		this.status = status;
	}

	public DateTime getDateTime()
	{
		return dateTime;
	}

	public void setDateTime( DateTime dateTime )
	{
		this.dateTime = dateTime;
	}
}
